<%@ page import="com.touzi.beans.dbs.users.User" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory" %>
<%@ page import="com.touzi.constants.DbCons" %>
<%@ page import="com.touzi.mapper.UserMapper" %>
<%@ page import="java.util.List" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%

%>

<%
    boolean isok=false;

    try {
        isok= (boolean) session.getAttribute("isok");
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (!isok) {
        String msg = "登陆失效，请退出后重新登陆！";
        response.sendRedirect("/admdeskjsps/msg.jsp?msg=" + URLEncoder.encode(msg, "utf-8"));
        return;
    }
    String username = (String) session.getAttribute("user");
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layPage快速使用</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body style="margin: auto;padding: 16px">
<button id="addnew" class="layui-btn" data-type="reload">添加新产品</button>

<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>


<script src="/layui/layui.js"></script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>

<script>
    layui.use('table', function () {
        var table = layui.table;
        var $ = layui.$;

        //方法级渲染
        table.render({
            elem: '#LAY_table_user'
            ,
            url: '/admdesk'
            ,
            where: {method: "chanpinlist"}
            ,
            cols: [[
                {field: 'id', title: 'ID'}
                , {field: 'biaoti', title: '标题'}
                , {field: 'jiage', title: '价格'}
                , {field: 'fenhong', title: '分红'}
                , {field: 'fenhongcishu', title: '分红次数'}
                , {field: 'fenhongzhouqi', title: '分红周期'}
                , {field: 'shengyu', title: '剩余'}
                , {field: 'paixu', title: '排序'}
                , {field: 'keyong', title: '可用'}
                , {tile: '操作', align: 'center', toolbar: '#barDemo'}
            ]]
            ,
            id: 'testReload'
            ,
            page: {
                limit: 30,
                layout: ['prev', 'page', 'next', 'count', 'skip', 'refresh'],
                next: '下一页',
                prev: '上一页',
                groups: 10
            }
        });

        table.on('tool(user)', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent === 'edit') {
                layer.open({
                    type: 2,
                    content: "/admdeskjsps/chanpinxiugai.jsp?chanpinid=" + data['id'],
                    area: ['430px','400px'],
                    offset: 'auto'
                });
            }
        });

        $("#addnew").on("click", function () {
            layer.open({
                type: 2,
                content: "/admdeskjsps/addchanpin.jsp",
                area: ['430px', '400px'],
                offset: 'auto'
            });
        })

    });

</script>
</body>
</html>